package com.mustafaiev.tair.cts.service;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.mustafaiev.tair.cts.dto.PayerDTO;
import com.mustafaiev.tair.cts.exeption.DataNotRetrievedException;

public class CostsTrackingSystemUserDetailsService implements
		UserDetailsService {

	private static final Logger LOGGER = Logger
			.getLogger(CostsTrackingSystemUserDetailsService.class);

	@Autowired
	private PayerService payerService;

	@Override
	public UserDetails loadUserByUsername(final String email)
			throws UsernameNotFoundException {
		PayerDTO payer = null;
		try {
			payer = this.payerService.retrieveActiveByEmail(email);
		} catch (final DataNotRetrievedException e) {
			LOGGER.error(e.getLocalizedMessage(), e);
		}
		return payer;
	}

}
